package com.example.send.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 主题模式  根据with 匹配规则到对应的队列  *表示匹配一个词，#可以匹配多个词
 */
@Configuration
public class RabbitmqTopicConfig {

    public static final String TOPIC_EXCHANGE = "topic_exchange";

    public static final String QUEUE_TOPIC_1 = "queueTopic1";
    public static final String QUEUE_TOPIC_2 = "queueTopic2";
    public static final String QUEUE_TOPIC_3 = "queueTopic3";


    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(TOPIC_EXCHANGE, true, false);
    }

    @Bean
    public Queue queueTopic1() {
        return new Queue(QUEUE_TOPIC_1, true, false, false);
    }

    @Bean
    public Queue queueTopic2() {
        return new Queue(QUEUE_TOPIC_2, true, false, false);
    }

    @Bean
    public Queue queueTopic3() {
        return new Queue(QUEUE_TOPIC_3, true, false, false);
    }

    @Bean
    public Binding topicBinding1() {
        return BindingBuilder.bind(queueTopic1()).to(topicExchange()).with("topic.message");
    }

    @Bean
    public Binding topicBinding2() {
        return BindingBuilder.bind(queueTopic2()).to(topicExchange()).with("topic.#");
    }

    @Bean
    public Binding topicBinding3() {
        return BindingBuilder.bind(queueTopic3()).to(topicExchange()).with("topic.*");
    }
}

